package com.itheima.app.controller;

import com.itheima.app.manager.TestSoulManager;
import com.itheima.vo.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 测灵魂
 *
 * @author bug
 */
@RestController
public class TestSoulController {

    @Autowired
    private TestSoulManager testSoulManager;

    // 问卷调查
    @GetMapping("/testSoul")
    public ResponseEntity testSoulQuestion() {
        return testSoulManager.testSoulQuestion();
    }

    // 提交问卷
    @PostMapping("/testSoul")
    public ResponseEntity commitAnswers(@RequestBody Map<String, List<Answer>> map) {
        // 获取请求参数
        List<Answer> answerList = map.get("answers");
        // 调用manager
        return testSoulManager.commitAnswers(answerList);
    }

    // 查看结果
    @GetMapping("/testSoul/report/{reportId}")
    public ResponseEntity report(@PathVariable Integer reportId) {
        return testSoulManager.report(reportId);
    }


}
